package designMode.compoundPattern;

/**
 * @author LIBOFEI
 * @ClassName QuackCounter
 * @description QuackCounter是一个装饰者，用来统计叫的次数，和适配器一样，需要实现目标接口
 * @date 2020/7/1 14:43
 * @Version 1.0
 **/
public class QuackCounter implements Quackable {

    private Quackable quackable;
    private static int numberOfQuacks;

    public QuackCounter(Quackable quackable){
        this.quackable = quackable;
    }

    @Override
    public void quack() {
        quackable.quack();
        //增加行为
        numberOfQuacks++;
    }

    public static int getNumberOfQuacks() {
        return numberOfQuacks;
    }

    @Override
    public void registerObserver(Observer observer) {
        quackable.registerObserver(observer);
    }

    @Override
    public void notifyObservers() {
        quackable.notifyObservers();
    }
}


